<?php
/**
 * Setting Form
 *
 * @category   Cms
 * @package    Cms_Form
 */
class Cms_Form_System_Setting_Form extends BIS_Form_Abstract
{
    public function init()
    {
        $this->addElementPrefixPath('Cms_Decorator',
                            	     APPLICATION_PATH . '/modules/cms/models/decorator/',
                            	    'decorator');
        
        $this->setMethod('post');
        $this->setAction('');
        $this->setModel(new Cms_Model_System());

        $systemSetting = $this->getModel()->getSetting();

        $this->addElement('text', 'companyName', array(
            'label' => 'Company Name',
            'size' => 30,
            'filters' => array('StringTrim'),
            'required' => true
        ));

        $this->addElement('hidden', 'companyLogo', array(
            'label' => 'Company Logo',
            'value' => $systemSetting->companyLogo,
            'required' => true,
            'decorators' => array(
                            'ViewHelper',
                            array(array('image' => 'HtmlTag'),  array('tag' =>'img', 'src' =>$systemSetting->companyLogo, 'id' =>'logo', 'placement' => 'APPEND')),
                            'FormElementsErrors',
                             array(array('data' => 'HtmlTag'),  array('tag' =>'td')),
                              'FormElementsLabel',
                            array(array('row' => 'HtmlTag'), array('tag' => 'tr'))
                        )
        ));
        
        $this->addElement('textarea', 'companyAddress', array(
            'label' => 'Company Address',
            'rows' => 5,
            'cols' => 50,
            'filters' => array('StringTrim'),
            'required' => true
        ));

        $this->addElement('text', 'companyEmail', array(
            'filters'    => array('StringTrim', 'StringToLower'),
            'validators' => array('EmailAddress',
                array('StringLength', true, array(3, 128))
            ),
            'label' => 'E-Mail',
            'size' => 30,
            'required' => true
        ));

        $this->addElement('text', 'companyPhone', array(
            'label' => 'Phone',
            'size' => 30,
            'filters' => array('StringTrim'),
            'required' => true
        ));

        $this->addElement('text', 'companyFax', array(
            'label' => 'Fax',
            'size' => 30,
            'filters' => array('StringTrim')
        ));

        //Email Setting
        $this->addElement('select', 'mailProtocol', array(
            'label' => 'Mail Protocol',
            'description' => 'Only choose \'Mail\' unless your host has disabled the php mail function.',
            'multiOptions' => array('mail' => "Mail", 'smtp' => "SMTP")
        ));

        $this->addElement('text', 'mailParameters', array(
            'label' => 'Mail Parameters',
            'size' => 30,
            'filters' => array('StringTrim'),
            'description' => 'When using \'Mail\', additional mail parameters can be added here (e.g. "-femail@companyaddress.com").'
        ));

        $this->addElement('text', 'smtpHost', array(
            'label' => 'SMTP Host',
            'size' => 30,
            'filters' => array('StringTrim')
        ));

        $this->addElement('text', 'smtpUsername', array(
            'label' => 'SMTP Username',
            'size' => 30,
            'filters' => array('StringTrim')
        ));

        $this->addElement('text', 'smtpPassword', array(
            'label' => 'SMTP Password',
            'size' => 30,
            'filters' => array('StringTrim')
        ));

        $this->addElement('select', 'smtpConnection', array(
            'label' => 'SMTP Connection',
            'multiOptions' => array('tls' => "TLS", 'ssl' => "SSL")
        ));

        $this->addElement('text', 'smtpPort', array(
            'label' => 'SMTP Port',
            'size' => 5,
            'filters' => array('Null'),
            'validators' => array('Int')
        ));

        $this->addElement('text', 'smtpTimeout', array(
            'label' => 'SMTP Timeout',
            'size' => 5,
            'filters' => array('Null'),
            'validators' => array('Int')
        ));

        $this->addElement('radio', 'alertMail', array(
            'label' => 'Alert Mail',
            'validators' => array('Int'),
            'multiOptions' => array(1=>"Yes", 0=> "No"),
            'separator' => '',
            'description' => '(Send a email to the company email when a new sale is made.)'
        ));

        $this->addElement('textarea', 'additionalAlertMails', array(
            'label' => 'Additional Alert E-Mails',
            'rows' => 5,
            'cols' => 40,
            'filters' => array('StringTrim'),
            'description' => 'Any additional emails you want to receive the alert email, in addition to the main company email. (comma separated)'
        ));

        //option setting
        $this->addElement('text', 'invoiceStartNumber', array(
            'label' => 'Invoice Start No',
            'size' => 5,
            'required' => true,
            'validators' => array('Int'),
            'description' => 'Set the starting number the invoices will begin from.'
        ));

         $this->addElement('text', 'invoiceNumberThreshold', array(
            'label' => 'Invoice No Threshold',
            'size' => 5,
            'required' => true,
            'validators' => array('Int'),
            'description' => 'Threshold for adding leading zeros (number of digits that will prevent the adding of additional zeros).'
        ));

         $this->addElement('text', 'invoicePrefix', array(
            'label' => 'Invoice Prefix',
            'size' => 5,
            'description' => 'Set the invoice prefix e.g. IN/001'
        ));

        $this->addElement('text', 'invoiceSuffix', array(
            'label' => 'Invoice Suffix',
            'size' => 5,
            'description' => 'Set the invoice suffix'
        ));

        $this->addElement('text', 'currencySymbol', array(
            'label' => 'Currency Symbol',
            'size' => 5,
            'required' => true,
            'filters' => array('StringTrim'),
            'validators' => array(array('StringLength',true, array(1,12))),
            'description' => 'Set the currency symbol e.g. ₦'
        ));

        $this->addElement('text', 'currencyCode', array(
            'label' => 'Currency Code',
            'size' => 5,
            'required' => true,
            'filters' => array('StringTrim'),
            'validators' => array(array('StringLength',true, array(1,3))),
            'description' => 'Set the currency code e.g. NGN'
        ));

        $this->setElementDecorators(array(
            'ViewHelper',
            'FormElementsErrors',
             array(array('data' => 'HtmlTag'),  array('tag' =>'td')),
              'FormElementsLabel',
            array(array('row' => 'HtmlTag'), array('tag' => 'tr'))
        ),
            array(
                'companyLogo'
            ),
            false
        );
        
       $this->addDisplayGroup(
            array('companyName', 'companyLogo', 'companyAddress', 'companyEmail', 'companyPhone','companyFax'),
            'general',
            array('decorators' => array('FormElements',
                array(array('tablewrapper' => 'HtmlTag'), array('tag' => 'table', 'class' => 'form')),
                array(array('divwrapper' => 'HtmlTag'), array('tag' => 'div', 'id' => 'tab_general'))
                ))
        );
   
       $this->addDisplayGroup(
            array('mailProtocol', 'mailParameters', 'smtpHost', 'smtpHost', 'smtpUsername', 'smtpPassword',
                  'smtpConnection', 'smtpPort', 'smtpTimeout', 'alertMail', 'additionalAlertMails'),
            'mail',
            array('decorators' => array('FormElements',
                array(array('tablewrapper' => 'HtmlTag'), array('tag' => 'table', 'class' => 'form')),
                array(array('divwrapper' => 'HtmlTag'), array('tag' => 'div', 'id' => 'tab_mail'))
                ))
        );

       $this->addDisplayGroup(
            array('invoiceStartNumber', 'invoiceNumberThreshold', 'invoicePrefix', 'invoiceSuffix', 'currencySymbol', 'currencyCode'),
            'option',
            array('decorators' => array('FormElements',
                array(array('tablewrapper' => 'HtmlTag'), array('tag' => 'table', 'class' => 'form')),
                array(array('divwrapper' => 'HtmlTag'), array('tag' => 'div', 'id' => 'tab_option'))
                ))
        );

        $this->setDecorators(array(
            'FormElements',
            'Form'
        ));

    }
}